app.controller("route", ["$scope", "$rootScope","$interval","$location", "$state", "$http", function($scope, $rootScope,$interval,$location, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'route';
	$(".shadow").css({
		"display": "none"
	})
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'House/roadlist',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
			href:$location.absUrl()
		}
	}).success(function(data) {
		console.log(data)
		if(data["status"] == 0) {
			$scope.page.rongcuo = true
			$scope.routlist = data["list"]
			$scope.num = data["num"]
		} else {
			$scope.page.rongcuo = false
			$scope.routlist = data["list"]
			$scope.num = data["num"]
//			for(var j=0;j<data["list"].length;j++){
			$scope.today = new Date().getTime()/1000
			showtimes()		
				function showtimes() {
					setTimeout(function(){
					$scope.today = new Date().getTime()/1000
					var times = document.querySelectorAll(".times")
					for(var i = 0; i < times.length; i++) {
						var a =times[i].getAttribute("data-info")
						var d = parseInt(a / (60 * 60)/24) <= 9 ? "0" + parseInt(a / (60 * 60)/24) : parseInt(a / (60 * 60)/24);
						var h = parseInt(a /3600%24) <= 9 ? "0" + parseInt(a /3600%24) : parseInt(a /3600%24);
						var m = parseInt(a /24% 60) <= 9 ? "0" + parseInt(a/24 % 60) : parseInt(a/24 % 60)
						var s = parseInt(a % 60) <= 9 ? "0" + parseInt(a % 60) : parseInt(a % 60)
						if(s < 0) {
							s = 60 + s;
							m = m - 1;
						}
						if(m < 0) {
							m = 60 + m;
							h = h - 1;
						}
						if(h < 0) {
							h = 24 + h;
							d = d-1
						}
					times[i].innerHTML= d +"天"+" "+ h + "时"+" " + m + "分"+" " + s + "秒"
					}
				},1)
				}	
			var timeout = $interval(function() {
				showtimes()
				}, 1000)	
				$scope.$on('$destroy', function() {
				$interval.cancel(timeout);
				})
//		}	
			}
		$scope.toroutInfo = function(id) {
			console.log(id)
			$state.go("main.routeInfo", {
				Id: id
			})
		}

		function price(sort) { //价格排序
			$http({
				method: 'post',
				url: '' + $rootScope.Location + 'House/roadlist',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				data: {
					user_Id: localStorage.getItem("user_ID"),
					token: localStorage.getItem("token"),
					price_sort: sort,
				}
			}).success(function(data) {
				//				console.log(data)
				if(data["status"] == 0) {
					$scope.page.rongcuo = true
					$scope.routlist = data["list"]
					$scope.num = data["num"]
				} else {
					$scope.page.rongcuo = false
					$scope.routlist = data["list"]
					$scope.num = data["num"]
				}
			})
		}

		function time(sort) { //时间排序
			$http({
				method: 'post',
				url: '' + $rootScope.Location + 'House/roadlist',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				data: {
					user_Id: localStorage.getItem("user_ID"),
					token: localStorage.getItem("token"),
					time_sort: sort,
				}
			}).success(function(data) {
				//				console.log(data)
				if(data["status"] == 0) {
					$scope.page.rongcuo = true
					$scope.routlist = data["list"]
					$scope.num = data["num"]
				} else {
					$scope.page.rongcuo = false
					$scope.routlist = data["list"]
					$scope.num = data["num"]
				}
			})
		}

		function moods(sort) { //价格排序
			$http({
				method: 'post',
				url: '' + $rootScope.Location + 'House/roadlist',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				data: {
					user_Id: localStorage.getItem("user_ID"),
					token: localStorage.getItem("token"),
					moods_sort: sort,
				}
			}).success(function(data) {
				//				console.log(data)
				if(data["status"] == 0) {
					$scope.page.rongcuo = true
					$scope.routlist = data["list"]
					$scope.num = data["num"]
				} else {
					$scope.page.rongcuo = false
					$scope.routlist = data["list"]
					$scope.num = data["num"]
				}
			})
		}
		var sort = 1
		var sort2 = 1
		var sort3 = 1
		$(".Price").click(function() { //点击价格排序
			if($(this).find("i").attr("class") == "iconfont icon-xiangxia") {
				$(this).find("i").addClass("icon-xiangshang").removeClass("")
				$(this).siblings().find("i").removeClass("icon-xiangshang")
			} else {
				$(this).find("i").addClass("icon-xiangxia").removeClass("icon-xiangshang")
					//				$(this).siblings().find("i").removeClass("icon-xiangshang")
			}
			sort++
			if(sort % 2 == 1) {
				sort = 1
				price(sort)
			} else {
				sort = 2
				price(sort)
			}
		})
		$(".Time").click(function() { //点击价格排序
			if($(this).find("i").attr("class") == "iconfont icon-xiangxia") {
				$(this).find("i").addClass("icon-xiangshang").removeClass("")
				$(this).siblings().find("i").removeClass("icon-xiangshang")
			} else {
				$(this).find("i").addClass("icon-xiangxia").removeClass("icon-xiangshang")
			}
			sort2++
			if(sort2 % 2 == 1) {
				sort2 = 1
				time(sort2)
			} else {
				sort2 = 2
				time(sort2)
			}
		})
		$(".Moods").click(function() { //点击价格排序
			if($(this).find("i").attr("class") == "iconfont icon-xiangxia") {
				$(this).find("i").addClass("icon-xiangshang").removeClass("")
				$(this).siblings().find("i").removeClass("icon-xiangshang")
			} else {
				$(this).find("i").addClass("icon-xiangxia").removeClass("icon-xiangshang")
			}
			sort3++
			if(sort3 % 2 == 1) {
				sort3 = 1
				moods(sort3)
			} else {
				sort3 = 2
				moods(sort3)
			}
		})
	})
}])

app.controller("project", ["$scope", "$rootScope", "$state","$location","$http", function($scope, $rootScope, $state,$location, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'project';
	//		$scope.Timer = function(){
	//			$(".choose_ul").find(".iconfont").eq(2).css({"color":"red"})
	//			$(".time_list").find("i").eq(2).show()		}
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'House/houses_list',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
		data: {
			user_Id: localStorage.getItem("user_ID"),
			token: localStorage.getItem("token"),
			href:$location.absUrl()
		}
	}).success(function(data) {
		console.log(data)
		if(data["list"]) {
			$scope.page.rongcuo = false
			$scope.Data = data
			$scope.dataPrice = data["price"]
			$scope.dataHouse = data["house"]
		} else {
			$scope.page.rongcuo = true
		}

	})
	$scope.goprojectInfo = function(Id, type) {
			if(type == 2) {
				$state.go("main.newprojectInfo", {
					Id: Id
				})
			} else {
				$state.go("main.projectInfo", {
					Id: Id
				})
			}
		}
		//价格排序
		//	var flag = true
	$(".findPrice").click(function() {

		if($(this).find(".time_list").css("display") == "none") {
			$(".shadow2").show()
			$(this).find(".time_list").show()
			$(this).siblings().find(".time_list").hide()
		} else {
			$(".shadow2").hide()
			$(this).find(".time_list").hide()
			$(this).siblings().find(".time_list").hide()
		}

	})
	var price = ""
	setTimeout(function() {
			$("#findPrice ul li").click(function() {
				$(this).addClass("active").siblings().removeClass("active")
				price = $(this).attr("data-info")
				console.log(price)
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'House/houses_list',
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: {
						user_Id: localStorage.getItem("user_ID"),
						token: localStorage.getItem("token"),
						price: price
					}
				}).success(function(data) {
					console.log(data)
					if(data["list"]) {
						$scope.page.rongcuo = false
						$scope.Data = data
					} else {
						$scope.Data = ''
						$scope.page.rongcuo = true
					}
					$(this).parent().parent().hide()
					$(".shadow2").hide()
				})
			})
		}, 1000)
		//户型排序	
	$(".findType").click(function() {
		if($(this).find(".time_list").css("display") == "none") {
			$(".shadow2").show()
			$(this).find(".time_list").show()
			$(this).siblings().find(".time_list").hide()
		} else {
			$(".shadow2").hide()
			$(this).find(".time_list").hide()
			$(this).siblings().find(".time_list").hide()
		}
	})
	var houses = ""
	setTimeout(function() {
			$("#findType ul li").click(function() {
				$(this).addClass("active").siblings().removeClass("active")
				houses = $(this).attr("data-Info")
				console.log(houses)
				$http({
					method: 'post',
					url: '' + $rootScope.Location + 'House/houses_list',
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: {
						user_Id: localStorage.getItem("user_ID"),
						token: localStorage.getItem("token"),
						houses: houses
					}
				}).success(function(data) {
					console.log(data)
					if(data["list"]) {
						$scope.page.rongcuo = false
						$scope.Data = data
					} else {
						$scope.Data = ''
						$scope.page.rongcuo = true
					}
					$(this).parent().parent().hide()
					$(".shadow2").hide()
				})
			})
		}, 1000)
		//	$("#txt_area").click(function(){
	var selectArea4 = new MobileSelectArea();
	selectArea4.init({
		trigger: '#txt_area',
		value: $('#txt_area').val(),
		data: []
	});
	$.get('js/areaJson_upd0427.json', function(result) {
			selectArea4.settings.data = result.data;
			selectArea4.data = result.data;
	})
		//	})
}])